var express = require('express'),
  redis = require('redis');

var client = redis.createClient();
var app = express.createServer();

var counter = 0;

app.get('/submit', function(req, res) {
  pushOnQueue(req, res);

  res.send('job submitted.' + counter);
});

function pushOnQueue(req, res) {
  requestNumber = counter++;
  console.log('got request.' + requestNumber);
  

  message = JSON.stringify({
  	"class": "RequestProcessor",
  	"args": [{"node_id": requestNumber, "url": req.url}]
  });

  client.rpush('resque:queue:requests', message);
}

app.listen(8777);
console.log('Server running at http://127.0.0.1:8777/');